package com.googlecode.uipipedream;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.Icon;
import javax.swing.JLabel;

/**
 * <p>
 * This file is part of UIPipeDream.
 * </p>
 * 
 * <p>
 * You can redistribute UIPipeDream and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 * </p>
 * 
 * <p>
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * </p>
 * 
 * <p>
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <a
 * href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>.
 * </p>
 * 
 * @author <a href="http://daemonsadvocate.blogspot.com/">Matthew B. Gray</a>
 * @author James Jones
 * @version 1.0 Final
 */
public class JVerticalLabel extends JLabel {
	private static final long serialVersionUID = 3634083459332685335L;
	private static final double THETA_RADIANS = Math.PI / 2;

	public JVerticalLabel(String text) {
		super(text);
	}

	public JVerticalLabel(Icon image) {
		super(image);
	}

	@Override
	public Dimension getPreferredSize() {
		Dimension d = super.getPreferredSize();
		return new Dimension(d.height, d.width); // Swap width and height
	}

	@Override
	public void paint(Graphics g) {
		/*
		 * g2d.translate(h, 0); g2d.rotate(1.5708); //apprx 90 degrees CW
		 * 
		 * it becomes: g2d.translate(0, w); g2d.rotate(-1.5708); //approx 90
		 * degrees CCW
		 * 
		 * If you want to rotate 180 degrees (rotate PI radians):
		 * g2d.translate(h, w); g2d.rotate(Math.PI); // 180 degrees
		 */
		Graphics2D g2d = (Graphics2D) g;
		g2d.rotate(THETA_RADIANS);
		g2d.translate(10, 10);
		super.paint(g2d);
	}
}
